

import React from 'react'
import {Switch,Redirect,Route} from 'react-router-dom'
import routers from './router.config' 

function fliterRouter(props){
  return(
    props.map((item,key)=>{
      if(item.to) return <Redirect key={key} from={item.from} to={item.to}/>
      return <Route key={key} path={item.path} render={ routes => <item.component {...routes} routers={item.children} /> } />
    })
  )
}

export default function router() {
  return(
     <Switch>
      {fliterRouter(routers)}
    </Switch>
  )
 

}
